

package com.hexinfo.dmpro.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hexinfo.dmpro.admin.model.SysDictDetail;
import com.hexinfo.dmpro.admin.service.SysDictDetailService;
import com.hexinfo.dmpro.common.annotation.Log;
import liquibase.pro.packaged.S;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import com.hexinfo.dmpro.admin.model.SysDict;
import com.hexinfo.dmpro.admin.service.SysDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 字典表
 *
 * @author zhouax
 * @date 2023-08-10 19:33:55
 */
@RestController
@AllArgsConstructor
@RequestMapping("/api/dict" )
@Api(value = "sysdict", tags = "字典表管理")
public class SysDictController {

    private final  SysDictService sysDictService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param sysDict 字典表
     * WrapperEnhancer.like(sysDict); //自动拼接存在值sql的方法
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public ResponseEntity<Object> getSysDictPage(Page page, SysDict sysDict) {
        return ResponseEntity.ok(sysDictService.queryList(page,sysDict));
    }


    /**
     * 通过id查询字典表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public ResponseEntity<Object> getById(@PathVariable("id" ) Long id) {
        return ResponseEntity.ok(sysDictService.getById(id));
    }

    /**
     * 新增字典表
     * @param sysDict 字典表
     * @return R
     */
    @ApiOperation(value = "新增字典表", notes = "新增字典表")
    @PostMapping
    public ResponseEntity<Object> save(@RequestBody SysDict sysDict) {
        return ResponseEntity.ok(sysDictService.save(sysDict));
    }

    /**
     * 修改字典表
     * @param sysDict 字典表
     * @return R
     */
    @ApiOperation(value = "修改字典表", notes = "修改字典表")
    @PutMapping
    public ResponseEntity<Object> updateById(@RequestBody SysDict sysDict) {
        return ResponseEntity.ok(sysDictService.updateById(sysDict));
    }

    /**
     * 通过id删除字典表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除字典表", notes = "通过id删除字典表")
    @DeleteMapping("/{id}" )
    public ResponseEntity<Object> removeById(@PathVariable Long id) {
        return ResponseEntity.ok(sysDictService.removeById(id));
    }

    /**
     * 按字典名获取子字典列表
     * @return
     */
    @GetMapping("/dictDetail" )
    public ResponseEntity<Object> dictDetail(String dictName) {
        return ResponseEntity.ok(sysDictService.dictDetail(dictName));
    }
}
